﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using lumo.input;
using Microsoft.Xna.Framework.Input;
using lumo.display.object2D;
using lumo;
using lumo.display.animation2D;
using lumo.display.gui;
using lumo.display.light;
using game.character;

namespace game.scene
{


    public class SceneMap : lumo.scene.IScene
    {

        game.display.object2d.SpritesetMap Spriteset;
        game.display.hud.HUD _HUD;

        /// <summary>
        /// Start the scene
        /// </summary>
        /// <param name="Game"></param>
        public void Start(lumo.LumoComponent Component)
        {
            Microsoft.Xna.Framework.Media.Song song = Component.Content.Load<Microsoft.Xna.Framework.Media.Song>("Audio/BGM/Aquatic Ambience");
            Microsoft.Xna.Framework.Media.MediaPlayer.Play(song);
            Microsoft.Xna.Framework.Media.MediaPlayer.IsRepeating = true;

            Global.Map = new GameMap(Component);
            Global.CursorSprite.Texture = Component.Content.Load<Texture2D>("Graphics/Cursors/Cursor");
            Global.CursorSprite.Origin = new Vector2(Global.CursorSprite.Texture.Width / 2, Global.CursorSprite.Texture.Height / 2);

            Tiled level = Component.Content.Load<Tiled>("Levels/Level02");
            Global.Map.Setup(Component, level);

            //Submarine    = new GamePlayer(Component.Content.Load<Texture2D>("Graphics/Misc/Submarino 96"));
            Spriteset    = new game.display.object2d.SpritesetMap(Component, Global.Map);

            _HUD = new display.hud.HUD(Component);
            _HUD.Lives.MaxLives = 3;
            _HUD.Lives.Lives = 3;

            Console.WriteLine("" + Global.Map.Player.Battler.HP + "/" + Global.Map.Player.Battler.MaxHP);
            _HUD.Health.Setup(0, Global.Map.Player.Battler.HP, Global.Map.Player.Battler.MaxHP);

            _HUD.Route.Setup(0, Global.Map.Player.Position.X, Global.Map.Width * Global.Map.Tiled.TileWidth);
        }

        /// <summary>
        /// Terminate the scene
        /// </summary>
        /// <param name="Game"></param>
        public void Terminate(lumo.LumoComponent Component)
        {
        }

        /// <summary>
        /// Update the scene.
        /// </summary>
        /// <param name="Game"></param>
        public void Update(lumo.LumoComponent Component)
        {
            Global.Map.Update(Component);
            Spriteset.Update(Component, Global.Camera);

            _HUD.Route.Current = Global.Map.Player.Position.X;
            _HUD.Health.Current = Global.Map.Player.Battler.HP;

            _HUD.Update(Component);

            if (_HUD.Timer.Finished)
                Component.Scene = new SceneGameOver();
        }

        /// <summary>
        /// Draw the scene.
        /// </summary>
        /// <param name="Game"></param>
        public void Draw(lumo.LumoComponent Component)
        {
            // Set variables
            GraphicsDevice GraphicsDevice = Component.GraphicsDevice;
            SpriteBatch    SpriteBatch    = Component.SpriteBatch;

            Spriteset.Draw(Component, Global.Map.LightManager);
            SpriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, Global.ScreenMatrix);

            _HUD.Draw(Component.SpriteBatch);

            Global.CursorSprite.Draw(Component.SpriteBatch);

            SpriteBatch.End();
        }
    }
}
